<%@ page language="java" pageEncoding="UTF-8"
%>

<link rel="stylesheet" type="text/css" media="all" href="${pageContext.request.contextPath}/js/bootstrap/daterangepicker/bootstrap.css?v=1.0.1.1&t=${commonAppTimestamp}" />
<link rel="stylesheet" type="text/css" media="all" href="${pageContext.request.contextPath}/js/bootstrap/daterangepicker/daterangepicker.css?v=1.0.1.2&t=${commonAppTimestamp}" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap/daterangepicker/date.js?v=1.0.1.1&t=${commonAppTimestamp}"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap/daterangepicker/daterangepicker.js?v=1.0.1.1&t=${commonAppTimestamp}"></script>
         
<script type="text/javascript">
<!--//--><![CDATA[//><!--

!function ($) {


 $.fn.dt_range_picker = function (setting) {
 
 	 var container =  $(this);
 	 
 	 var date_start = setting.date_start;
 	 var date_end = setting.date_end;
 	 var callback = setting.callback;
 	 
 	 $('#' + date_start).val( Date.parse('yesterday').toString('yyyy-MM-dd') );
 	 $('#' + date_end).val( Date.parse('yesterday').toString('yyyy-MM-dd') );
	 container.val(Date.parse('yesterday').toString('yyyy-MM-dd') + ' 至 ' + Date.parse('yesterday').toString('yyyy-MM-dd'));

	 var oldVal = container.val();
	 var oldStartVal =  $('#' + date_start).val();
	 var oldEndVal =  $('#' + date_end).val();
	 
     $(this).daterangepicker({
		ranges: {
		  // '今天': ['today', 'today'],
		   '昨天':   ['yesterday', 'yesterday'],
		   '最近七天': [ Date.today().add({ days: -7 }), 'yesterday'],
		   '上周':     [ Date.today().moveToDayOfWeek(1, -1), 'yesterday'],
		   '最近30天': [ Date.today().add({ days: -30 }), 'yesterday'],
		   '本月':    [ Date.today().moveToFirstDayOfMonth(), Date.today().moveToLastDayOfMonth()],
		   '上个月':  [ Date.today().moveToFirstDayOfMonth().add({ months: -1 }), Date.today().moveToFirstDayOfMonth().add({ days: -1 })],
		   '本年':    [ Date.january(), 'yesterday']
		},
		opens: 'right',
		format: 'yyyy-MM-dd',
		separator: ' 至 ',
		startDate: 'yesterday',
		endDate: 'yesterday',
		minDate: '2012-08-01',
		maxDate: Date.today().add({ days: -1 }).toString('yyyy-MM-dd'),
		locale: {
			applyLabel: '确定',
			clearLabel: '取消',
			fromLabel: '从',
			toLabel: '至',
			customRangeLabel: '自定义范围',
			daysOfWeek: ['日','一', '二', '三', '四', '五','六'],
			monthNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
			firstDay: 1
		},
		showWeekNumbers: false,
	 	onchange:  function(start, end) {
	 
	 		app_log( start.toString('yyyy-MM-dd') + ' year: ' + start.getFullYear() + ' month: ' + start.getMonth() );
			app_log( end.toString('yyyy-MM-dd')   + ' year: ' +   end.getFullYear() + ' month: ' +   end.getMonth());
			
			
			//app_log( start.toString('yyyy-MM-dd') + ' year: ' + start.getFullYear() + ' month: ' + start.getMonth() );
			//app_log( end.toString('yyyy-MM-dd')   + ' year: ' +   end.getFullYear() + ' month: ' +   end.getMonth());
			
			var isOutOfMonth = false;
			if( start.getFullYear() == end.getFullYear() ){
			
				isOutOfMonth = (end.getMonth() - start.getMonth() > 2 ) ? true : false;

			}else{
				isOutOfMonth = ( (end.getMonth()+12) - start.getMonth() > 2 ) ? true : false;
			
			}

		
			if( isOutOfMonth ){ 
				$(this).val(oldVal);
				
				alert('查询时间跨度需在3个自然月内。');
				
				//app_log( container.val(oldVal) );
				
				
				$('#' + date_start).val( oldStartVal );
 	 			$('#' + date_end).val( oldEndVal );
 	 			
			}else{
				$('#' + date_start).val( start.toString('yyyy-MM-dd') );
 	 			$('#' + date_end).val( end.toString('yyyy-MM-dd') );
			}
			
	 
	 	}

	 });

  

 };
    

} (window.jQuery);


//--><!
</script>